package com.lizemin.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionIdListener;

/**
 * @author lzm
 * @date 2025/4/6 12:56
 * @description sessionId监听器，用于监听sessionId的变化
 */
@Slf4j
@Component
public class MySessionIdListener implements HttpSessionIdListener {

    @Autowired
    SessionManagementListener sessionManagementListener;

    @Override
    public void sessionIdChanged(HttpSessionEvent se, String oldSessionId) {
        log.info("sessionId已更改，从{}变成了{}", oldSessionId, se.getSession().getId());
        sessionManagementListener.refreshSession(oldSessionId, se.getSession().getId());
    }
}
